﻿@{
    ViewBag.Title = "Home Page";
}

<ol class="round">

    <ul id="tree" class="ztree"></ul>
    <div><input type="checkbox" name="isOnlyModel" id="isOnlyModel" />是否只生成实体</div>
    <div><input type="button" onclick="CheckAll()" value="全选" /> <input type="button" onclick="    RefreshTree()" value="刷新" />  <input type="button" onclick="    GenerateCode()" value="生成选中表" />  <input type="button" onclick="GenerateDBContext()" value="生成DBCntext" /></div>
    <div><span id="errorinfo"></span></div>
</ol>


<script>
    <!--
var setting = {
    check: {
        enable: true
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    view: {
        showIcon: false
    }
};

    $(document).ready(function () {
        LoadTree();
    });

    function LoadTree() {
        var url = "/Home/GetTableList";
        $.getJSON(url, function (result) {
            $.fn.zTree.init($("#tree"), setting, result);
        });
    }

    function RefreshTree() {
        LoadTree();
    }

    function CheckAll() {
        var treeObj = $.fn.zTree.getZTreeObj("tree");
        treeObj.checkAllNodes(true);
    }

    function GenerateCode() {
        var zTree = $.fn.zTree.getZTreeObj("tree");
        var nodes = zTree.getChangeCheckedNodes();
        if (nodes.length <= 0) {
            Dialog.alert("请选择要生成的表！");
            return;
        }
        $.post("/Home/GenerateCode", { data: JSON.stringify(nodes) ,isOnlyModel:$("#isOnlyModel").prop("checked")}, function (result) {
            if (result.IsSuccess) {
                $("#errorinfo").html(result.ErrorInfo);
            }
            else {
                alert("no");
            }
        });
    }

    function GenerateDBContext() {
        $.post("/Home/GenerateDBContext", function (result) {
            if (result.IsSuccess) {
                $("#errorinfo").html(result.ErrorInfo);
            }
            else {
                alert("no");
            }
        });
    }
    //-->
</script>